import java.util.Scanner;

class homework1 {
    public static long factorial(long number) {
        if (number <= 1)
            return 1;
        else
            return number * factorial(number - 1);
    }

    public static double scale(double num, int dig)
    {
        return Double.valueOf(String.format("%.2f", num));
    }

    public static void fac() {
        //加
        Scanner input= new Scanner(System.in);
        System.out.println("输入两个数");
        float n1=input.nextFloat();
        double n2=input.nextDouble();
        double sum=n2+(double)n1;
        sum=scale(sum, 2);
        System.out.println(sum);

        //阶乘
        System.out.println("输入阶乘n");
        int n3=input.nextInt();
        if(n3>=1 && n3<=10)
        {
            long result=factorial((long)n3);
            System.out.println(result);
        }
        else
            System.out.println("范围错误");

        //n次方
        System.out.println("几的几次方");
        float n4=input.nextFloat();
        int n5=input.nextInt();
        System.out.println(Math.pow(n5,n4));
    }

    public static void BMI() {
        Scanner input= new Scanner(System.in);
        System.out.println("请输入体重(kg)");
        float kg=input.nextFloat();
        System.out.println("请输入身高(m)");
        float m=input.nextFloat();
        float bmi=kg/(m*m);
        System.out.println(bmi);
    }

    public static void strCmp() {
        String s1 = new String("aaa");
        String s2 = new String("aaa");
        if(s1==s2)
            System.out.println("s 1 true");
        if(s1.equals(s2))
            System.out.println("s 2 true");

        StringBuilder sb1 = new StringBuilder();
        sb1.append("aaa");
        StringBuilder sb2 = new StringBuilder();
        sb2.append("aaa");
        if(sb1==sb2)
            System.out.println("sb 1 true");
        if(sb1.equals(sb2))
            System.out.println("sb 2 true");
        
        StringBuffer sbf1 = new StringBuffer();
            sbf1.append("aaa");
        StringBuffer sbf2 = new StringBuffer();
            sbf2.append("aaa");
        if(sbf1==sbf2)
                System.out.println("sfb 1 true");
        if(sbf1.equals(sbf2))
                System.out.println("sfb 2 true");

        System.out.println(s1.isEmpty());
        System.out.println(sb1.length()==0);
        System.out.println(sbf1.length()==0);
    }

    public static void pack() {
        Integer i = 10;
        int i2 = i;
        System.out.println(i);
        System.out.println(i2);
    }

    public static void main(String[] args) {
        System.out.println("add & fac");
        fac();
        System.out.println("BMI");
        BMI();
        System.out.println("strCmp");
        strCmp();
        System.out.println("package");
        pack();
    }
}